// 双指针查找法
function twoSum1(nums: number[], target: number): number[] {
    const arr = nums.map((v, i) => ({ val: v, ind: i }));
    arr.sort((a, b) => a.val - b.val);
    let l = 0;
    let r = arr.length - 1;
    while (l < r) {
        const leftItem = arr[l];
        const rightItem = arr[r];
        const sum = leftItem.val + rightItem.val;
        if (sum === target) {
            return [leftItem.ind, rightItem.ind];
        } else if (sum > target) {
            r--;
        } else {
            l++;
        }
    }
    return []
};
